//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "GaussGegenbauerIntegration.h"
using namespace Cephei::QL::Math::Integrals;
#include <gen/QL/Math/Integrals/GaussianOrthogonalPolynomial.h>
#include <gen/QL/Math/Integrals/GaussianQuadrature.h>
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::Integrals::CGaussGegenbauerIntegration::CGaussGegenbauerIntegration (UInt64 n, Double lambda) : CGaussianQuadrature(CGaussGegenbauerIntegration::typeid)
{
    try
    {
#ifdef HANDLE
        _phGaussGegenbauerIntegration = NULL;
#endif
        QuantLib::Size _n = (QuantLib::Size)ValueHelper::Convert (n);
        QuantLib::Real _lambda = (QuantLib::Real)ValueHelper::Convert (lambda);
        _ppGaussGegenbauerIntegration = new boost::shared_ptr<QuantLib::GaussGegenbauerIntegration> (new QuantLib::GaussGegenbauerIntegration ( _n,  _lambda ));
        SetGaussianQuadrature (boost::dynamic_pointer_cast<QuantLib::GaussianQuadrature> (*_ppGaussGegenbauerIntegration));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Math::Integrals::CGaussGegenbauerIntegration::CGaussGegenbauerIntegration (boost::shared_ptr<QuantLib::GaussGegenbauerIntegration>& childNative, Object^ owner) : CGaussianQuadrature(CGaussGegenbauerIntegration::typeid)
{
#ifdef HANDLE
	_phGaussGegenbauerIntegration = NULL;
#endif
	_ppGaussGegenbauerIntegration = &childNative;
    _ppGaussianQuadrature = new boost::shared_ptr<QuantLib::GaussianQuadrature> (boost::dynamic_pointer_cast<QuantLib::GaussianQuadrature> (*_ppGaussGegenbauerIntegration));
}
Cephei::QL::Math::Integrals::CGaussGegenbauerIntegration::CGaussGegenbauerIntegration (QuantLib::GaussGegenbauerIntegration& childNative, Object^ owner) : CGaussianQuadrature(CGaussGegenbauerIntegration::typeid)
{
#ifdef HANDLE
	_phGaussGegenbauerIntegration = NULL;
#endif
	_ppGaussGegenbauerIntegration = new boost::shared_ptr<QuantLib::GaussGegenbauerIntegration> (&childNative);
    _ppGaussianQuadrature = new boost::shared_ptr<QuantLib::GaussianQuadrature> (boost::dynamic_pointer_cast<QuantLib::GaussianQuadrature> (*_ppGaussGegenbauerIntegration));
    _GaussGegenbauerIntegrationOwner = owner;
    _GaussianQuadratureOwner = owner;
}

Cephei::QL::Math::Integrals::CGaussGegenbauerIntegration::CGaussGegenbauerIntegration (CGaussGegenbauerIntegration^ copy) : CGaussianQuadrature(CGaussGegenbauerIntegration::typeid)
{
#ifdef HANDLE
	_phGaussGegenbauerIntegration = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppGaussGegenbauerIntegration = new boost::shared_ptr<QuantLib::GaussGegenbauerIntegration> (copy->GetShared());
        _ppGaussianQuadrature = new boost::shared_ptr<QuantLib::GaussianQuadrature> (boost::dynamic_pointer_cast<QuantLib::GaussianQuadrature> (*_ppGaussGegenbauerIntegration));
    }
}
Cephei::QL::Math::Integrals::CGaussGegenbauerIntegration::CGaussGegenbauerIntegration (System::Type^ t) : CGaussianQuadrature(CGaussGegenbauerIntegration::typeid)
{
#ifdef HANDLE
	_phGaussGegenbauerIntegration = NULL;
#endif
	if (!t->IsSubclassOf(CGaussGegenbauerIntegration::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::Integrals::CGaussGegenbauerIntegration::CGaussGegenbauerIntegration (QuantLib::Handle<QuantLib::GaussGegenbauerIntegration>& childNative, Object^ owner)  : CGaussianQuadrature(CGaussGegenbauerIntegration::typeid)
{
	_phGaussGegenbauerIntegration = &childNative;
	_ppGaussGegenbauerIntegration = &static_cast<boost::shared_ptr<QuantLib::GaussGegenbauerIntegration>>(childNative.currentLink());
    _ppGaussianQuadrature = new boost::shared_ptr<QuantLib::GaussianQuadrature> (boost::dynamic_pointer_cast<QuantLib::GaussianQuadrature> (*_ppGaussGegenbauerIntegration));
    _GaussGegenbauerIntegrationOwner = owner;
}
Cephei::QL::Math::Integrals::CGaussGegenbauerIntegration::CGaussGegenbauerIntegration (QuantLib::Handle<QuantLib::GaussGegenbauerIntegration> childNative)  : CGaussianQuadrature(CGaussGegenbauerIntegration::typeid)
{
	_phGaussGegenbauerIntegration = &childNative;
	_ppGaussGegenbauerIntegration = &static_cast<boost::shared_ptr<QuantLib::GaussGegenbauerIntegration>>(childNative.currentLink());
    _ppGaussianQuadrature = new boost::shared_ptr<QuantLib::GaussianQuadrature> (boost::dynamic_pointer_cast<QuantLib::GaussianQuadrature> (*_ppGaussGegenbauerIntegration));
}
#endif
#ifdef STRUCT
Cephei::QL::Math::Integrals::CGaussGegenbauerIntegration::CGaussGegenbauerIntegration (QuantLib::GaussGegenbauerIntegration childNative)  : CGaussianQuadrature(CGaussGegenbauerIntegration::typeid)
{
#ifdef HANDLE
	_phGaussGegenbauerIntegration = NULL;
#endif
	_ppGaussGegenbauerIntegration = new boost::shared_ptr<QuantLib::GaussGegenbauerIntegration> (new QuantLib::GaussGegenbauerIntegration (childNative));
    _ppGaussianQuadrature = new boost::shared_ptr<QuantLib::GaussianQuadrature> (boost::dynamic_pointer_cast<QuantLib::GaussianQuadrature> (*_ppGaussGegenbauerIntegration));
}
#endif

Cephei::QL::Math::Integrals::CGaussGegenbauerIntegration::~CGaussGegenbauerIntegration ()
{
    if (_ppGaussGegenbauerIntegration != NULL)
    {
	    delete _ppGaussGegenbauerIntegration;
        _ppGaussGegenbauerIntegration = NULL;
    }
}
Cephei::QL::Math::Integrals::CGaussGegenbauerIntegration::!CGaussGegenbauerIntegration ()
{
    if (_ppGaussGegenbauerIntegration != NULL)
    {
	    delete _ppGaussGegenbauerIntegration;
    }
}
QuantLib::GaussGegenbauerIntegration& Cephei::QL::Math::Integrals::CGaussGegenbauerIntegration::GetReference ()
{
    if (_ppGaussGegenbauerIntegration == NULL) throw gcnew NativeNullException ();
	return **_ppGaussGegenbauerIntegration;
}
boost::shared_ptr<QuantLib::GaussGegenbauerIntegration>& Cephei::QL::Math::Integrals::CGaussGegenbauerIntegration::GetShared ()
{
    if (_ppGaussGegenbauerIntegration == NULL) throw gcnew NativeNullException ();
	return *_ppGaussGegenbauerIntegration;
}
QuantLib::GaussGegenbauerIntegration* Cephei::QL::Math::Integrals::CGaussGegenbauerIntegration::GetPointer ()
{
    if (_ppGaussGegenbauerIntegration == NULL) throw gcnew NativeNullException ();
	return &**_ppGaussGegenbauerIntegration;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::GaussGegenbauerIntegration>& Cephei::QL::Math::Integrals::CGaussGegenbauerIntegration::GetHandle ()
{
	if (_phGaussGegenbauerIntegration == NULL)
	{
		_phGaussGegenbauerIntegration = new Handle<QuantLib::GaussGegenbauerIntegration> (*_ppGaussGegenbauerIntegration);
	}
	return *_phGaussGegenbauerIntegration;
}
#endif
bool Cephei::QL::Math::Integrals::CGaussGegenbauerIntegration::HasNative () 
{
	return (_ppGaussGegenbauerIntegration != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Math::Integrals::IGaussGegenbauerIntegration^ Cephei::QL::Math::Integrals::CGaussGegenbauerIntegration_Factory::Create (UInt64 n, Double lambda)
{
    return gcnew CGaussGegenbauerIntegration ( n,  lambda);
}
